package com.fxnotes;

import com.fxnotes.book.BookModule;
import com.fxnotes.common.thread.TaskExecutor;
import com.fxnotes.common.thread.TaskFxExecutor;
import com.fxnotes.common.ui.ModuleController;
import com.fxnotes.page.PageModule;
import com.google.common.eventbus.EventBus;
import com.google.inject.AbstractModule;
import com.google.inject.TypeLiteral;
import com.google.inject.multibindings.Multibinder;
import com.fxnotes.database.inmemory.repository.BookRepository;
import com.fxnotes.database.inmemory.repository.ChapterRepository;
import com.fxnotes.database.inmemory.repository.PageRepository;
import com.fxnotes.domain.repository.IBookRepository;
import com.fxnotes.domain.repository.IChapterRepository;
import com.fxnotes.domain.repository.IPageRepository;

public class GuiceModule extends AbstractModule {

    @Override
    protected void configure() {
        configureCommon();
        configureDataBase();
        configureUI();
    }

    protected void configureCommon() {
        bind(TaskExecutor.class).to(TaskFxExecutor.class);
        bind(EventBus.class).asEagerSingleton();
    }

    protected void configureDataBase() {
        bind(IBookRepository.class).to(BookRepository.class);
        bind(IChapterRepository.class).to(ChapterRepository.class);
        bind(IPageRepository.class).to(PageRepository.class);
    }

    protected void configureUI() {
        Multibinder<ModuleController> binder = Multibinder.newSetBinder(
                binder(),
                new TypeLiteral<ModuleController>() {
                });
        binder.addBinding().to(BookModule.class);
        binder.addBinding().to(PageModule.class);
    }
}
